package com.ruoyi.consulte.policy.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.consulte.policy.mapper.PolicyMapper;
import com.ruoyi.consulte.policy.domain.Policy;
import com.ruoyi.consulte.policy.service.IPolicyService;

/**
 * 政策Service业务层处理
 *
 * @author duanxinli
 * @date 2023-11-06
 */
@Service
public class PolicyServiceImpl implements IPolicyService {
    @Autowired
    private PolicyMapper policyMapper;

    /**
     * 查询政策
     *
     * @param id 政策主键
     * @return 政策
     */
    @Override
    public Policy selectPolicyById(String id) {
        return policyMapper.selectPolicyById(id);
    }

    /**
     * 查询政策列表
     *
     * @param policy 政策
     * @return 政策
     */
    @Override
    public List<Policy> selectPolicyList(Policy policy) {
        return policyMapper.selectPolicyList(policy);
    }

    /**
     * 新增政策
     *
     * @param policy 政策
     * @return 结果
     */
    @Override
    public int insertPolicy(Policy policy) {
        policy.setId(IdUtils.fastUUID());
        if (policy.getCreateDate()==null){
            policy.setCreateDate(DateUtils.getNowDate());
        }
        String username = SecurityUtils.getUsername();
        policy.setCreateBy(username);
        policy.setSort(0L);
        return policyMapper.insertPolicy(policy);
    }

    /**
     * 修改政策
     *
     * @param policy 政策
     * @return 结果
     */
    @Override
    public int updatePolicy(Policy policy) {
        return policyMapper.updatePolicy(policy);
    }

    /**
     * 批量删除政策
     *
     * @param ids 需要删除的政策主键
     * @return 结果
     */
    @Override
    public int deletePolicyByIds(String[] ids) {
        return policyMapper.deletePolicyByIds(ids);
    }

    /**
     * 删除政策信息
     *
     * @param id 政策主键
     * @return 结果
     */
    @Override
    public int deletePolicyById(String id) {
        return policyMapper.deletePolicyById(id);
    }
}
